<?php
class TagLibCms extends TagLib{
    protected $tags = array(
        "arclist" => array("attr"=>"name,typeid,flag,order,channelid,page,row,child","close"=>1),//文档列表
        "arctags" => array("attr"=>"aid,row","close"=>0),//获取tag列表
        "load" => array("attr"=>"file","close"=>0),//包含文件标签
        "taglist" => array("attr"=>"name,row,order","close"=>1),//调用标签列表
    );
    
    /**
     * 文档列表标签
     * //标签参数
     * //name 用于循环体内数组变量名
     * //typeid  指定分类id 默认为0
     * //flag   指定文章标记属性，多个标记以","隔开，如 flag="h,c"
     * //order  排序字段，默认DESC，其他排序方式加|隔开，如order="totalcc" 或 order="totalcc|ASC"，默认为"id|DESC"
     * //channelid  指定频道模型id 默认为1
     * //page 指定第几页，和row连用，默认为1
     * //row  调用几条,和page联合使用，默认为10，例：page="1" row="10" 效果等同于limit 0,10
     * //child 是否调用子分类下文档，当指定typeid时并且该参数为true时有效，例：child="true",默认为false  
     */
    public function _arclist($attr,$content){
        $tag = $this->parseXmlAttr($attr, 'arclist');
        $name = $tag['name'];
        $typeid = empty($tag['typeid'])?"0":$tag['typeid'];//分类id
        $ctype = empty($tag['child']) ? 'false' : $tag['child'];
        $page = empty($tag['page']) ? '1' : $tag['page'];
        $row = empty($tag['row']) ? '10' : $tag['row'];
        $order=empty($tag['order'])?"id|desc":$tag['order'];
        $flag=empty($tag['flag'])?"":$tag['flag'];
        $channelid=empty($tag['channelid'])?"1":$tag['channelid'];
        //$filed = empty($tag['filed']) ? 'true' : $tag['filed'];

        $parse = '<?php ';
        
        $parse .= '$__LIST__ = D(\'CArchive\')->page(' . $page . ',' . $row . ')->GetArcList(';
        $parse .= "'{$typeid}','{$order}','{$flag}','{$channelid}','1',true,{$ctype}";
        $parse .= ');';
        $parse .= ' ?>';
        $parse .= '<volist name="__LIST__" id="' . $name . '">';
        $parse .= $content;
        $parse .= '</volist>';
        return $parse;
    }
    
    public function _arctags($attr,$content){
        $tag=$this->parseXmlAttr($attr, "arctags");
        $aid = empty($tag['aid'])?"":$this->autoBuildVar($tag['aid']);
        $row = empty($tag['row'])?0:$tag['row'];
        if($aid==""){
            return "";
        }
        $parse="<?php echo D('CTags')->GetTagsLink({$aid},'{$row}');?>";
        return $parse;
        
    }
    //模板中包含文件，替代include标签
    public  function _load($attr,$content){
        $attr=$this->parseXmlAttr($attr, "include");//初始化属性
        if(!isset($attr['file'])) return "";
        $filepath=GetTplPath($attr['file']);
        if(empty($filepath)){
            return "";
        }
        $str="<?php \n include '{$filepath}';\n?>";
        return $str;
    }
    
    //tag列表
    function _taglist($attr,$content){
        $tag = $this->parseXmlAttr($attr, 'taglist');
        $name = $tag['name'];
        $row = empty($tag['row']) ? '10' : $tag['row'];
        $parse = '<?php ';
        
        $parse .= '$__LIST__ = D(\'CTags\')->GetTagList(';
        $parse .= "{$row}";
        $parse .= ');';
        $parse .= ' ?>';
        $parse .= '<volist name="__LIST__" id="' . $name . '">';
        $parse .= $content;
        $parse .= '</volist>';
        return $parse;
    }
    
}
